package com.baor.web.controller.finance;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.baor.common.annotation.Log;
import com.baor.common.core.controller.BaseController;
import com.baor.common.core.domain.AjaxResult;
import com.baor.common.enums.BusinessType;
import com.baor.finance.domain.Refund;
import com.baor.finance.service.IRefundService;
import com.baor.common.utils.poi.ExcelUtil;
import com.baor.common.core.page.TableDataInfo;

/**
 * 会员退款Controller
 * 
 * @author ruoyi
 * @date 2025-07-18
 */
@RestController
@RequestMapping("/finance/refund")
public class RefundController extends BaseController
{
    @Autowired
    private IRefundService refundService;

    /**
     * 查询会员退款列表
     */
    @PreAuthorize("@ss.hasPermi('finance:refund:list')")
    @GetMapping("/list")
    public TableDataInfo list(Refund refund)
    {
        startPage();
        List<Refund> list = refundService.selectRefundList(refund);
        return getDataTable(list);
    }

    /**
     * 导出会员退款列表
     */
    @PreAuthorize("@ss.hasPermi('finance:refund:export')")
    @Log(title = "会员退款", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Refund refund)
    {
        List<Refund> list = refundService.selectRefundList(refund);
        ExcelUtil<Refund> util = new ExcelUtil<Refund>(Refund.class);
        util.exportExcel(response, list, "会员退款数据");
    }

    /**
     * 获取会员退款详细信息
     */
    @PreAuthorize("@ss.hasPermi('finance:refund:query')")
    @GetMapping(value = "/{refundId}")
    public AjaxResult getInfo(@PathVariable("refundId") Long refundId)
    {
        return success(refundService.selectRefundByRefundId(refundId));
    }

    /**
     * 新增会员退款
     */
    @PreAuthorize("@ss.hasPermi('finance:refund:add')")
    @Log(title = "会员退款", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Refund refund)
    {
        return toAjax(refundService.insertRefund(refund));
    }

    /**
     * 修改会员退款
     */
    @PreAuthorize("@ss.hasPermi('finance:refund:edit')")
    @Log(title = "会员退款", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Refund refund)
    {
        return toAjax(refundService.updateRefund(refund));
    }

    /**
     * 删除会员退款
     */
    @PreAuthorize("@ss.hasPermi('finance:refund:remove')")
    @Log(title = "会员退款", businessType = BusinessType.DELETE)
	@DeleteMapping("/{refundIds}")
    public AjaxResult remove(@PathVariable Long[] refundIds)
    {
        return toAjax(refundService.deleteRefundByRefundIds(refundIds));
    }

    //同意退款
    @GetMapping("/yesType/{refundId}")
    public AjaxResult yseType(@PathVariable Long refundId){
        return toAjax(refundService.changeType(refundId));
    }

    //退款审核失败
    @GetMapping("/noType/{refundId}")
    public AjaxResult noType(@PathVariable Long refundId){
        return toAjax(refundService.changeType2(refundId));
    }
}
